package ro.gateway.aida.fnd;

import java.util.ArrayList;

import ro.gateway.aida.obj.AIDAActivityObject;
import ro.gateway.aida.obj.GenericActivityProperty;



/**
 * <p>Title: Romanian AIDA</p>
 * <p>Description: :D application</p>
 * <p>Copyright: Copyright (comparator) 2003</p>
 * <p>Company: Romania Development Gateway </p>
 * @author Mihai Popoaei, mihai_popoaei@yahoo.com, smike@intellisource.ro
 * @version 1.0-* @version $Id: FundingByCatItem.java,v 1.1 2004/10/24 23:37:13 mihaipostelnicu Exp $
 */
public class FundingByCatItem extends AIDAActivityObject
{
      private long funding_id = -1;
      private GenericActivityProperty component;
      private long amount = 0;
      private String currency;
      private ArrayList yearlyItems;

      public FundingByCatItem()
      {
            this.yearlyItems = new ArrayList();
            this.objectType = AIDAActivityObject.TYPE_FUNDING_BYCAT;
      }

      public void addYearlyItem( FundingYearlyItem item )
      {
            if ( !this.containsYearlyItem( item ) )
            {
                  this.yearlyItems.add( item );
                  item.setComponent( component );
            }
      }

      public boolean containsYearlyItem( FundingYearlyItem item )
      {
            for ( int i = 0; i < yearlyItems.size(); i++ )
            {
                  FundingYearlyItem fundingYearlyItem = ( FundingYearlyItem ) yearlyItems.get( i );
                  if ( fundingYearlyItem.equals( item ) )
                        return true;
            }

            return false;
      }

      public ArrayList getYearlyItems()
      {
            return yearlyItems;
      }

      public FundingYearlyItem[] getYearlyItemsArray()
      {
            if ( yearlyItems.size() > 0 )
            {
                  FundingYearlyItem[] result = new FundingYearlyItem[ yearlyItems.size() ];
                  yearlyItems.toArray( result );
                  return result;
            }
            else
            {
                  return null;
            }
      }

      public void removeYearlyItem( int index )
      {
            if ( ( index > 0 ) && ( index < yearlyItems.size() ) )
            {
                  yearlyItems.remove( index );
            }
      }

      public long getComponent_id()
      {
            if ( component != null )
            {
                  return component.getId();
            }
            return -1;
      }

      public void setFunding_id( long funding_id )
      {
            this.funding_id = funding_id;
            for ( int i = 0; i < yearlyItems.size(); i++ )
            {
                  FundingYearlyItem fundingYearlyItem = ( FundingYearlyItem ) yearlyItems.get( i );
                  fundingYearlyItem.setFunding_id( funding_id );
            }
      }

      public long getFunding_id()
      {
            return funding_id;
      }

      public void setCurrency( String currency )
      {
            this.currency = currency;
      }

      public void setAmount( long amount )
      {
            this.amount = amount;
      }

      public void setComponent( GenericActivityProperty component )
      {
            this.component = component;

            for ( int i = 0; i < yearlyItems.size(); i++ )
            {
                  FundingYearlyItem fundingYearlyItem = ( FundingYearlyItem ) yearlyItems.get( i );
                  fundingYearlyItem.setComponent( component );
            }
      }

      public String getCurrency()
      {
            return currency;
      }

      public long getAmount()
      {
            return amount;
      }

      public GenericActivityProperty getComponent()
      {
            return component;
      }

      public boolean isValid()
      {
            return ( currency != null )
                  && ( amount > 0 ) && ( component != null );
      }
}
